﻿using MangoMes.Commont.DapperHelps;
using MangoMes.Commont.Domain.Jocker;
using MangoMes.Commont.Domain.RBACs;
using MangoMes.Commont.DTOs;
using MangoMes.Commont.Infrastructures.Interfaces;
using MangoMes.Commont.Infrastructures.Repository;
using MediatR;
using static MangoMes.Commont.DapperHelps.DapperHelper;

namespace MangoMes.Write.API.Applications.warehousess
{
    public class warehouseCreateHandler : IRequestHandler<warehouseCreateCommond, ResultsDTO>
    {


        private readonly IBateRepository<Stashs> bate;

        public warehouseCreateHandler(IBateRepository<Stashs> bate)
        {
            this.bate = bate;
        }

        public async Task<ResultsDTO> Handle(warehouseCreateCommond request, CancellationToken cancellationToken)
        {

            try
            {
                var list = new ResultsDTO() { Code = 0 };

                var per = new Stashs()
                {
                    StashId=0,
                    StashName = request.StashName,
                    StashNum = request.StashNum,
                    Area = request.Area,
                    ChargeName = request.ChargeName,
                    isyes = request.isyes,
                    Position = request.Position,
                    TwoDimensionalCode = request.TwoDimensionalCode,
                    WarehouseNote = request.WarehouseNote,
                };
                DapperHelper dapperHelper = new DapperHelper();
                var str = "insert warehouselist values(@StashId,@StashNum,@StashName,@ChargeName,@Area,@Position,@WarehouseNote,@isyes,@TwoDimensionalCode)";
                var   id = await bate.Add(str, per, dapperHelper.MangoMesWrite);
                if(id>0)
                {
                    list.Message = "仓库添加成功";
                    list.Code = 1;
                }

                return list;

            }
            catch (Exception)
            {

                throw;
            }
           




        }






       
    }
}
